/* Reset and base styles for cross-browser compatibility */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    overflow: hidden;
    user-select: none;
    touch-action: manipulation;
}

/* Main container adapts to iframe or full screen */
#main-container {
    width: 100%;
    height: 450px; /* Default iframe height */
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Full screen mode detection */
@media (min-height: 500px) and (min-width: 800px) {
    #main-container {
        height: 90vh;
    }
}

/* Header tooltip - appears on hover over main panel */
#header-tooltip {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

#main-container:hover #header-tooltip {
    opacity: 1;
}

/* Control panel with optimized button layout */
#control-panel {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
}

#control-panel button {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: #4CAF50;
    color: white;
    cursor: pointer;
    font-size: 14px;
    min-height: 36px; /* Touch-friendly size */
    min-width: 36px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#control-panel button:hover {
    background: #45a049;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

#control-panel button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Main concept mapping area */
#concept-map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #ffffff;
    transform-origin: center center;
    transition: transform 0.3s ease;
}

/* SVG for connection lines */
#connection-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.connection-line {
    stroke: #666;
    stroke-width: 2;
    fill: none;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.connection-line.highlighted {
    stroke-width: 3;
    opacity: 1;
}

/* Central concept node */
#central-node {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 160px;
    height: 80px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    text-align: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    z-index: 10;
    line-height: 1.2;
}

/* Category headers - new drop zones for categorization */
.category-header {
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 10px;
    min-height: 120px;
    min-width: 200px;
    z-index: 2;
    transition: all 0.3s ease;
}

.category-header h4 {
    margin-bottom: 10px;
    text-align: center;
    font-size: 14px;
    color: #333;
}

.category-header.drop-active {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.1);
}

.category-header.complete {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.2);
}

/* Positioning for category headers */
.types-header {
    top: 20px;
    left: 20px;
}

.causes-header {
    top: 20px;
    right: 20px;
}

.effects-header {
    bottom: 20px;
    left: 20px;
}

.mitigation-header {
    bottom: 20px;
    right: 20px;
}

.stakeholders-header {
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

.drop-zone {
    min-height: 80px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: flex-start;
    align-content: flex-start;
}

/* Concept nodes with neutral color initially */
.concept-node {
    position: absolute;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 5;
    min-width: 100px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    word-wrap: break-word;
}

/* Neutral color for uncategorized nodes */
.concept-node.neutral {
    background: linear-gradient(135deg, #9e9e9e, #757575);
    color: white;
}

/* Category-based color coding - only applied when correctly categorized */
.concept-node.types {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
}

.concept-node.causes {
    background: linear-gradient(135deg, #ffa726, #ff9800);
    color: white;
}

.concept-node.effects {
    background: linear-gradient(135deg, #ab47bc, #9c27b0);
    color: white;
}

.concept-node.mitigation {
    background: linear-gradient(135deg, #66bb6a, #4caf50);
    color: white;
}

.concept-node.stakeholders {
    background: linear-gradient(135deg, #42a5f5, #2196f3);
    color: white;
}

/* Draggable states */
.concept-node.draggable:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.concept-node.dragging {
    transform: scale(1.1);
    opacity: 0.8;
    z-index: 100;
}

.concept-node.connected {
    border: 3px solid #4CAF50;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.5);
}

/* Nodes in drop zones have different positioning */
.concept-node.in-drop-zone {
    position: relative;
    margin: 2px;
}

/* Concept bank - initial positioning with jumbled layout */
.concept-bank {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Jumbled initial positions for concept nodes */
.concept-node.draggable:nth-child(1) { top: 80px; left: 300px; }
.concept-node.draggable:nth-child(2) { top: 150px; left: 400px; }
.concept-node.draggable:nth-child(3) { top: 200px; left: 250px; }
.concept-node.draggable:nth-child(4) { top: 120px; left: 500px; }
.concept-node.draggable:nth-child(5) { top: 180px; left: 350px; }
.concept-node.draggable:nth-child(6) { top: 100px; left: 450px; }
.concept-node.draggable:nth-child(7) { top: 220px; left: 300px; }
.concept-node.draggable:nth-child(8) { top: 160px; left: 200px; }
.concept-node.draggable:nth-child(9) { top: 90px; left: 350px; }
.concept-node.draggable:nth-child(10) { top: 240px; left: 400px; }
.concept-node.draggable:nth-child(11) { top: 110px; left: 250px; }
.concept-node.draggable:nth-child(12) { top: 190px; left: 450px; }
.concept-node.draggable:nth-child(13) { top: 130px; left: 300px; }
.concept-node.draggable:nth-child(14) { top: 210px; left: 350px; }
.concept-node.draggable:nth-child(15) { top: 170px; left: 500px; }
.concept-node.draggable:nth-child(16) { top: 140px; left: 200px; }
.concept-node.draggable:nth-child(17) { top: 230px; left: 250px; }
.concept-node.draggable:nth-child(18) { top: 80px; left: 400px; }
.concept-node.draggable:nth-child(19) { top: 200px; left: 300px; }
.concept-node.draggable:nth-child(20) { top: 120px; left: 450px; }
.concept-node.draggable:nth-child(21) { top: 180px; left: 200px; }
.concept-node.draggable:nth-child(22) { top: 100px; left: 350px; }

/* Template overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    background: white;
    padding: 20px;
    border-radius: 12px;
    max-width: 400px;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.overlay-content h3 {
    margin-bottom: 15px;
    color: #333;
}

.overlay-content ul {
    list-style: none;
    margin: 15px 0;
}

.overlay-content li {
    display: flex;
    align-items: center;
    margin: 8px 0;
}

.color-indicator {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    margin-right: 10px;
    display: inline-block;
}

.color-indicator.types { background: linear-gradient(135deg, #ff6b6b, #ee5a52); }
.color-indicator.causes { background: linear-gradient(135deg, #ffa726, #ff9800); }
.color-indicator.effects { background: linear-gradient(135deg, #ab47bc, #9c27b0); }
.color-indicator.mitigation { background: linear-gradient(135deg, #66bb6a, #4caf50); }
.color-indicator.stakeholders { background: linear-gradient(135deg, #42a5f5, #2196f3); }

#close-template {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 15px;
}

/* Information tooltip */
#info-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 10px;
    border-radius: 6px;
    font-size: 12px;
    max-width: 200px;
    z-index: 1001;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .concept-node {
        font-size: 12px;
        min-width: 80px;
        min-height: 32px;
        padding: 6px 8px;
    }
    
    #central-node {
        width: 140px;
        height: 70px;
        font-size: 14px;
    }
    
    #control-panel button {
        font-size: 12px;
        padding: 6px 8px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .category-header {
        min-width: 150px;
        min-height: 100px;
        padding: 8px;
    }
    
    .category-header h4 {
        font-size: 12px;
    }
}

/* Print styles */
@media print {
    #control-panel {
        display: none;
    }
    
    #main-container {
        height: 100vh;
    }
    
    .concept-node {
        box-shadow: none;
        border: 1px solid #333;
    }
}